<?php
class Admin_Form_Search_User extends Apps_Plugin_Grid_Search_Abstract {
    public function preInit() {
    	$dMapper = new M_Tool_DataMapper();
    	$tbUserGroup = new M_DbTable_UserGroup();

    	$listGroup = $dMapper->mapKeyValue(new M_DbTable_UserGroup(), 'id', 'name');

        $advancedCriteria = array(
            'id' => array(
                    'user.id',
                    self::$criteriaStringLike,
                    array(
                            'element'  => self::ELEMENT_TEXT,
                            'label'    => 'ID',
                    )
            ),
            'username' => array(
                    'user.username',
                    self::$criteriaStringLike,
                    array(
                            'element'  => self::ELEMENT_TEXT,
                            'label'    => 'Tên đăng nhập',
                    )
            ),
            'name' => array(
                    'user.full_name',
                    self::$criteriaStringLike,
                    array(
                            'element'  => self::ELEMENT_TEXT,
                            'label'    => 'Họ và tên',
                    )
            ),
            'usergroup' => array(
            		'user_group.id',
            		self::$criteriaSimple,
					array(
							'element'	   => self::ELEMENT_SELECT,
							'label'		   => 'Chức vụ',
							'multiOptions' => $listGroup
					)
            ),
            'phone' => array(
            		'user.phone',
            		self::$criteriaStringLike,
					array(
							'element'	   => self::ELEMENT_TEXT,
							'label'		   => 'Điện thoại',
					)
            ),
            'email' => array(
            		'user.email',
            		self::$criteriaStringLike,
					array(
							'element'	   => self::ELEMENT_TEXT,
							'label'		   => 'Email',
					)
            ),
            'address' => array(
            		'user.address',
            		self::$criteriaStringLike,
					array(
							'element'	   => self::ELEMENT_TEXT,
							'label'		   => 'Địa chỉ',
					)
            )
        );

        $simpleCriteria = array(
        		array('user.id LIKE ?', '%%%s%%'),
        		array('user.username LIKE ?', '%%%s%%'),
        		array('user.full_name LIKE ?', '%%%s%%'),
        		array('user.phone LIKE ?', '%%%s%%'),
        		array('user.email LIKE ?', '%%%s%%'),
        		array('user.address LIKE ?', '%%%s%%'),
        		array('user_group.name LIKE ?', '%%%s%%')
        );

        $this->setAdvCriteria($advancedCriteria);
        $this->setSplCriteria($simpleCriteria);
    }
}